package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.CpJydStatus;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.NumberUtil;
import com.ruoyi.system.domain.quality.QualityIncomingMaterial;
import com.ruoyi.system.mapper.QualityIncomingMaterialMapper;
import com.ruoyi.system.service.IQualityIncomingMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
;import java.util.List;

/**
 * @author GE-LV5
 * @create 2023/2/28 14:46
 */
@Service
@Slf4j
public class QualityIncomingMaterialServiceImpl extends ServiceImpl<QualityIncomingMaterialMapper, QualityIncomingMaterial> implements IQualityIncomingMaterialService {

    @Autowired
    QualityIncomingMaterialMapper qualityIncomingMaterialMapper;

    /**
     * 查询来料检验单
     *
     * @param vo
     * @return
     */
    @Override
    public List<QualityIncomingMaterial> selectQualityProcessInspection(QualityIncomingMaterial vo) {
        return qualityIncomingMaterialMapper.selectQualityProcessInspection(vo);
    }


    /**
     * 添加来料检验单
     *
     * @param quality 来料检验单
     * @return
     */
    @Override
    @Transactional
    public int insertQualityIncomingMaterial(QualityIncomingMaterial quality) {
        String number = NumberUtil.getNumber("22", "2023");
        quality.setIncomingCode(number);
        return qualityIncomingMaterialMapper.insertQualityIncomingMaterial(quality);
    }

    /**
     * 删除来料检验单
     *
     * @param id 总成计划主键
     * @return
     */
    @Override
    public int deleteQualityProcessInspectionById(Long id) {
        if (CpJydStatus.INSPECTION_CENTER.equals("1")) {
            throw new CustomException("来料检验中不能删除！");
        }
        return qualityIncomingMaterialMapper.deleteQualityProcessInspectionById(id);
    }


}
